/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.multioperacion.model;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author gabrielbran
 */
@Entity
@Table(name = "SUCURSAL", catalog = "", schema = "MULTIOPERACION")
@NamedQueries({
    @NamedQuery(name = "Sucursal.findAll", query = "SELECT s FROM Sucursal s"),
    @NamedQuery(name = "Sucursal.findByEmpresa", query = "SELECT s FROM Sucursal s WHERE s.sucursalPK.empresa = :empresa"),
    @NamedQuery(name = "Sucursal.findByCodigo", query = "SELECT s FROM Sucursal s WHERE s.sucursalPK.codigo = :codigo"),
    @NamedQuery(name = "Sucursal.findByServidor", query = "SELECT s FROM Sucursal s WHERE s.servidor = :servidor"),
    @NamedQuery(name = "Sucursal.findByNombre", query = "SELECT s FROM Sucursal s WHERE s.nombre = :nombre")})
public class Sucursal implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected SucursalPK sucursalPK;
    @Basic(optional = false)
    @Column(name = "SERVIDOR", nullable = false, length = 100)
    private String servidor;
    @Basic(optional = false)
    @Column(name = "NOMBRE", nullable = false, length = 100)
    private String nombre;
    @JoinColumn(name = "EMPRESA", referencedColumnName = "CODIGO", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Empresa empresa1;

    public Sucursal() {
    }

    public Sucursal(SucursalPK sucursalPK) {
        this.sucursalPK = sucursalPK;
    }

    public Sucursal(SucursalPK sucursalPK, String servidor, String nombre) {
        this.sucursalPK = sucursalPK;
        this.servidor = servidor;
        this.nombre = nombre;
    }

    public Sucursal(long empresa, short codigo) {
        this.sucursalPK = new SucursalPK(empresa, codigo);
    }

    public SucursalPK getSucursalPK() {
        return sucursalPK;
    }

    public void setSucursalPK(SucursalPK sucursalPK) {
        this.sucursalPK = sucursalPK;
    }

    public String getServidor() {
        return servidor;
    }

    public void setServidor(String servidor) {
        this.servidor = servidor;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public Empresa getEmpresa1() {
        return empresa1;
    }

    public void setEmpresa1(Empresa empresa1) {
        this.empresa1 = empresa1;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (sucursalPK != null ? sucursalPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Sucursal)) {
            return false;
        }
        Sucursal other = (Sucursal) object;
        if ((this.sucursalPK == null && other.sucursalPK != null) || (this.sucursalPK != null && !this.sucursalPK.equals(other.sucursalPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.multioperacion.model.Sucursal[sucursalPK=" + sucursalPK + "]";
    }

}
